package com.bigmi.admin.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bigmi.admin.mapper.AdWmMapper;
import com.bigmi.admin.mapper.WmUserMapper;
import com.bigmi.admin.service.AdWmService;
import com.bigmi.model.admin.dto.AdWmUserDto;
import com.bigmi.model.common.dtos.PageResponseResult;
import com.bigmi.model.common.dtos.ResponseResult;
import com.bigmi.model.common.enums.AppHttpCodeEnum;
import com.bigmi.model.wemedia.pojos.WmUser;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class AdWmServiceImpl extends ServiceImpl<AdWmMapper, WmUser> implements AdWmService {
    @Autowired
    private WmUserMapper wmUserMapper;

    @Override
    public ResponseResult saw(AdWmUserDto adWmUserDto) {
        if (adWmUserDto == null){
            return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST);
        }
        adWmUserDto.checkParam();
        //条件查询
        IPage page=new Page(adWmUserDto.getPage(),adWmUserDto.getSize());
        LambdaQueryWrapper<WmUser> queryWrapper =new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(adWmUserDto.getName())){
            queryWrapper.like(WmUser::getName,adWmUserDto.getName());
        }
        //按时间倒叙排序
        queryWrapper.orderByDesc(WmUser::getCreatedTime);

        page=page(page,queryWrapper);
        ResponseResult responseResult = new PageResponseResult(adWmUserDto.getPage(), adWmUserDto.getSize(), (int) page.getTotal());
        responseResult.setData(page.getRecords());
        List records = page.getRecords();
        log.info(""+records);
        log.info(""+responseResult);
        return responseResult;
    }

    @Override
    public ResponseResult upData(WmUser wmUser) {
        if (wmUser==null){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        System.out.println(wmUser);
        //审核状态
        wmUser.setStatus(wmUser.getStatus());
        System.out.println(wmUser);
        wmUserMapper.updateById(wmUser);

        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
}
